package com.ruoyi.community.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.mapper.OwnerGroupMemberMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.OwnerGroupMapper;
import com.ruoyi.community.domain.OwnerGroup;
import com.ruoyi.community.service.IOwnerGroupService;

/**
 * 群组列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-08-05
 */
@Service
public class OwnerGroupServiceImpl implements IOwnerGroupService 
{

    @Autowired
    private OwnerGroupMemberMapper ownerGroupMemberMapper;

    @Autowired
    private OwnerGroupMapper ownerGroupMapper;

    /**
     * 根据群组ID查询群组
     * 
     * @param groupId 群组ID
     * @return 群组列表
     */
    @Override
    public OwnerGroup selectOwnerGroupById(String groupId)
    {
        return ownerGroupMapper.selectOwnerGroupById(groupId);
    }

    /**
     * 根据queryParams查询群组
     * 
     * @param ownerGroup 群组信息
     * @return 群组列表
     */
    @Override
    public List<OwnerGroup> selectOwnerGroupList(OwnerGroup ownerGroup)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("groupName", ownerGroup.getGroupName());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        map.put("communityId", loginUser.getCommunityId());
        return ownerGroupMapper.selectOwnerGroupList(map);
    }

    /**
     * 新增群组列表
     * 
     * @param ownerGroup 群组列表
     * @return 结果
     */
    @Override
    public int insertOwnerGroup(OwnerGroup ownerGroup)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ownerGroup.setCreater(loginUser.getUsername());
        ownerGroup.setCommunityId(Long.valueOf(loginUser.getCommunityId()));
        return ownerGroupMapper.insertOwnerGroup(ownerGroup);
    }

    /**
     * 修改群组列表
     * 
     * @param ownerGroup 群组列表
     * @return 结果
     */
    @Override
    public int updateOwnerGroup(OwnerGroup ownerGroup)
    {
        return ownerGroupMapper.updateOwnerGroup(ownerGroup);
    }

    /**
     * 批量删除群组列表
     * 
     * @param groupIds 需要删除的群组列表ID
     * @return 结果
     */
    @Override
    public int deleteOwnerGroupByIds(String[] groupIds)
    {
        return ownerGroupMapper.deleteOwnerGroupByIds(groupIds);
    }

    /**
     * 删除群组列表信息
     * 
     * @param groupId 群组列表ID
     * @return 结果
     */
    @Override
    public int deleteOwnerGroupById(String groupId)
    {
        return ownerGroupMapper.deleteOwnerGroupById(groupId);
    }
}
